﻿using System.Security.Authentication;

namespace DoNet.Common.Helpers
{
    /// <summary>
    /// 
    /// </summary>
    public class SslHelper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sslArray"></param>
        /// <returns></returns>
        public static SslProtocols GetSsl(string[] sslArray)
        {
            SslProtocols sslProtocols = SslProtocols.None;
            bool containsNone = Array.Exists(sslArray, element => element == "None");
            bool containsTls12 = Array.Exists(sslArray, element => element == "Tls12");
            bool containsTls13 = Array.Exists(sslArray, element => element == "Tls13");
            if (!containsNone)
            {
                if (sslArray.Length == 1)
                {
                    if (containsTls12)
                    {
                        sslProtocols = SslProtocols.Tls12;
                    }
                    else if (containsTls13)
                    {
                        sslProtocols = SslProtocols.Tls13;
                    }
                }
                else
                {
                    if (containsTls12 && containsTls12)
                    {
                        sslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
                    }
                }
            }
            return sslProtocols;
        }
    }
}
